//-----------------Sonic CD Title Card Script-----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
private alias Object.Value0			:	Object.BarPos
private alias Object.Value1			:	Object.TextPos
private alias Object.Value2			:	Object.TextSize
private alias Object.Value3			:	Object.Timer
private alias Object.Value4			:	Object.FadeR
private alias Object.Value5			:	Object.FadeG
private alias Object.Value6			:	Object.FadeB
private alias Object.Value7			:	Object.CharPos

// SS Sonic aliases
private alias object.controlmode		:	SSSonic.ControlMode

// HUD Alias
private alias Object.Value1			:	HUD.TimeSeconds
private alias Object.Value2			:	HUD.TimeFrames

private alias object[10].value4 : Freddy.AI
private alias object[11].value4 : Bonnie.AI
private alias object[12].value4 : Chica.AI
private alias object[13].value4 : Foxy.AI
private alias object[14].value4 : Endo.AI
private alias object[15].value4 : GoldenFreddy.AI
private alias object[16].value4 : Puppet.AI
private alias object[17].value4 : Springtrap.AI

private alias object[18].value4 : WitheredFreddy.AI
private alias object[19].value4 : WitheredBonnie.AI
private alias object[20].value4 : WitheredChica.AI
private alias object[21].value4 : WitheredFoxy.AI

private alias object[22].value4 : BalloonBoy.AI
private alias object[23].value4 : JJ.AI

private alias object[24].value4 : ToyFreddy.AI
private alias object[25].value4 : ToyBonnie.AI
private alias object[26].value4 : ToyChica.AI
private alias object[27].value4 : Mangle.AI

private alias object[28].value4 : ShadowFreddy.AI
private alias object[29].value4 : ShadowBonnie.AI

// States
private alias 0	:	TITLECARD_FADEIN
private alias 1	:	TITLECARD_SLIDEIN
private alias 2	:	TITLECARD_DISPLAY
private alias 3	:	TITLECARD_SLIDEOUT

// Languages
private alias 0	:	LANG_ENGLISH
private alias 1	:	LANG_FRENCH
private alias 2	:	LANG_ITALIAN
private alias 3	:	LANG_DEUTSCH
private alias 4	:	LANG_SPANISH
private alias 5	:	LANG_JAPANESE

// ControlMode Aliases
private alias -1	:	CONTROLMODE_NONE
private alias  0	:	CONTROLMODE_NORMAL

// Game Mode Aliases
private alias 2	:	MODE_TIMEATTACK

// Priority
private alias 1	:	PRIORITY_ACTIVE



event ObjectDraw
	// Set the starting time values
	// (Rather than disabling the HUD timer while the title card is active,
	//  its values are simply reset here every frame until no longer needed)

	DrawRect(0, 0, screen.xsize, screen.ysize, 0, 0, 0, 255)
	switch Object.State
	case TITLECARD_FADEIN
		if Object.Timer > 0
			Object.Timer -= 8
		else
			// Make the Title Card start appearing
			PlaySfx(SfxName[Blip], 0)
			Object.State = TITLECARD_SLIDEIN
			Object.Timer = 0
		end if
		
		// Lock Sonic's control
		SSSonic.ControlMode = CONTROLMODE_NONE
		break
		
	case TITLECARD_SLIDEIN
		temp0  = 144
		temp0 += Object.CharPos
				

		if Object.TextPos > temp0
			// Slide the text to the left
			Object.TextPos -= 8
			
			// Now, this part got changed in an update
			
		else
			// -> Updated version - both the text AND the bar have to be on screen for the title card to progress

			if Object.BarPos == 0
				Object.State = TITLECARD_DISPLAY
			end if
		end if

		
		
		if Object.BarPos < 0
			// Move the Bar down
			Object.BarPos += 8
			
			// There used to be code here in older versions, but not anymore...
			// -> Initial version - only the bar needed to be in the proper position for the title card to continue
			//    This had text get incorrectly often
			
		end if
		break
		
	case TITLECARD_DISPLAY
		// Hold for a moment to let the Player see what a nice Title Card this is
		
		if Object.Timer == 100
			// Time's up, start sliding out!
            PlaySfx(SfxName[Blip], 0)
			Object.State = TITLECARD_SLIDEOUT
		else
			Object.Timer++
		end if
		break
		
	case TITLECARD_SLIDEOUT



		if Object.TextPos < 408
		
			// Move the text to the right, and...
			Object.TextPos += 4
			
			// ...move the bar upwards as well
			Object.BarPos -= 16
			
		else
			// The Title Card's job is done, despawn it
			object.type = TypeName[Blank Object]
            PlaySfx(SfxName[Fan3], 1)
			switch stage.actnum
			case 7
				CheckEqual(Freddy.AI, 20)
				temp2 = checkResult
				CheckEqual(Bonnie.AI, 20)
				temp2 &= checkResult
				CheckEqual(Chica.AI, 20)
				temp2 &= checkResult
				CheckEqual(Foxy.AI, 20)
				temp2 &= checkResult
				CheckEqual(Endo.AI, 20)
				temp2 &= checkResult
				CheckEqual(GoldenFreddy.AI, 20)
				temp2 &= checkResult
				CheckEqual(Puppet.AI, 20)
				temp2 &= checkResult
				CheckEqual(Springtrap.AI, 20)
				temp2 &= checkResult
				CheckEqual(WitheredFreddy.AI, 20)
				temp2 &= checkResult
				CheckEqual(WitheredBonnie.AI, 20)
				temp2 &= checkResult
				CheckEqual(WitheredChica.AI, 20)
				temp2 &= checkResult												
				CheckEqual(WitheredFoxy.AI, 20)
				temp2 &= checkResult
				CheckEqual(BalloonBoy.AI, 20)
				temp2 &= checkResult
				CheckEqual(JJ.AI, 20)
				temp2 &= checkResult
				CheckEqual(ToyFreddy.AI, 20)
				temp2 &= checkResult
				CheckEqual(ToyBonnie.AI, 20)
				temp2 &= checkResult
				CheckEqual(ToyChica.AI, 20)
				temp2 &= checkResult
				CheckEqual(Mangle.AI, 20)
				temp2 &= checkResult		
				CheckEqual(ShadowFreddy.AI, 20)
				temp2 &= checkResult					
				CheckEqual(ShadowBonnie.AI, 20)
				temp2 &= checkResult				
				if temp2 == 1
					PlayMusic(4)
				else
					PlayMusic(0)
				end if
			break
			default
				PlayMusic(0)
			break
			end switch	
			music.volume = 50
			
		end if
		break
		
	end switch
	
	// Before drawing, make sure this object hasn't been blanked already
	// (Under certain circumstances, this can otherwise cause major graphical issues!!)
	if Object.Type > TypeName[Blank Object]
        if object.state < TITLECARD_SLIDEOUT
            if object.state >= TITLECARD_SLIDEIN
            temp1 = Screen.xsize
            temp1 -= screen.xcenter
            temp1 -= 35
            DrawSpriteScreenXY(10, temp1, 115)	//NIGHT

            temp1 += 55
            DrawNumbers(0, temp1, 113, stage.actnum, 3, 8, 0)	//number
            end if
        end if
	end if
	
end event


event ObjectStartup
	
	// Load different sheets based on the Engine's current language

		// LANG_ENGLISH and LANG_JAPANESE share the same sheet
	LoadSpriteSheet("FNAF/Objects.gif")

	
	// Place the Title Card object into the level and setup its values
	Object[5].Type  = TypeName[TitleCard]
	Object[5].Timer = 384

	
	// Make the Title Card always active, and have it draw above everything
	Object[5].Priority  = PRIORITY_ACTIVE
	Object[5].DrawOrder = 6
	

	
	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	// 10 - Night
	SpriteFrame(0, 0, 36, 11, 753, 558)	    

end event


// ========================
// Editor events
// ========================

event RSDKDraw
	Object.TextSize = 12
	Object.TextSize += 8

	temp0 = 136
	temp0 += Object.CharPos
	temp0 <<= 16

	temp1 = 0x500000
	temp1 += Object.YPos
	
	DrawSpriteXY(0, Object.XPos, Object.YPos)
	DrawSpriteXY(5, Object.XPos, temp1)
	DrawSpriteXY(6, Object.XPos, temp1)
	DrawSpriteXY(7, Object.XPos, temp1)
	
	temp0 = 8
	while temp0 < Object.TextSize
		DrawSpriteXY(temp0, Object.XPos, temp1)
		temp0++
	loop
end event


event RSDKLoad
	LoadSpriteSheet("Special/ScoreScreen.gif")
	// 0 - Red Bar Frame
	SpriteFrame(0, 0, 32, 184, 224, 37)
	
	// 1-3 - Act Bubbles, not used here.
	SpriteFrame(96, 96, 48, 48, 41, 1)
	SpriteFrame(96, 96, 48, 48, 90, 1)
	SpriteFrame(96, 96, 48, 48, 139, 1)
	
	// 4 - "Zone" text, not used here.
	SpriteFrame(64, 97, 48, 16, 41, 67)
	
	// 5 - Main part of the "SONIC THE HEGDEHOG CD" bar
	SpriteFrame(72, 81, 160, 16, 60, 227)
	
	// 6 - Continuation of the Sonic CD bar
	SpriteFrame(16, 81, 160, 16, 52, 227)
	
	// 7 - Set of three lines
	SpriteFrame(100, 32, 24, 48, 182, 124)
	
	// 8-19 - Individual letters spelling out "Special Stage"
	SpriteFrame(0, 0, 16, 55, 207, 124)		// #8  - S
	SpriteFrame(17, 32, 10, 23, 176, 180)	// #9  - P
	SpriteFrame(28, 32, 9, 23, 187, 180)	// #10 - E
	SpriteFrame(38, 32, 8, 23, 197, 180)	// #11 - C
	SpriteFrame(47, 32, 6, 23, 206, 180)	// #12 - I
	SpriteFrame(54, 32, 11, 23, 212, 180)	// #13 - A
	SpriteFrame(66, 32, 9, 23, 176, 203)	// #14 - L
	
	SpriteFrame(0, 56, 16, 55, 207, 124)	// #15 - S
	SpriteFrame(17, 56, 10, 23, 186, 203)	// #16 - T
	SpriteFrame(28, 56, 11, 23, 212, 180)	// #17 - A
	SpriteFrame(40, 56, 10, 23, 197, 203)	// #18 - G
	SpriteFrame(51, 56, 9, 23, 187, 180)	// #19 - E

	SpriteFrame(-128,-128,256,0,256,256) //20	

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
